export class HttpManager {
    static getWordInfo(word: string) {
        let url = `http://apis.juhe.cn/idioms/query?wd=${word}&key=461e44d8e17f3154fdd6dc6aa53536d3`;
        return new Promise<null>((resolve, reject) => {
            let request = new XMLHttpRequest();
            request.open('GET', url, true);
            request.timeout = 5000;
            request.onreadystatechange = function () {
                if (request.readyState == 4) {
                    let statusCode = request.status;
                    if (statusCode == 200) {
                        let response = request.responseText;
                        let responseJson = JSON.parse(response);
                        resolve(responseJson);
                    } else {
                        reject(request);
                    }
                }
            };
            request.send();
        })
    }
}